package com.es.pay.ctmGrade;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;

import com.es.main.LoginUserBeen;
import com.es.util.common.AreaBen;
import com.es.util.common.CommonBiz;
import com.es.util.page.PageBean;
import com.es.util.page.PageNavigator;
import com.opensymphony.webwork.interceptor.ServletRequestAware;
import com.opensymphony.xwork.ActionSupport;

public class RetrieveCtmGradeListAction  extends ActionSupport implements ServletRequestAware{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	HttpServletRequest request;
	 
	   public String execute()throws Exception
	   {
		   String queryyyyymm = request.getParameter("queryyyyymm")==null?"":request.getParameter("queryyyyymm");
		   String queryCtmCode = request.getParameter("queryCtmCode")==null?"":request.getParameter("queryCtmCode");
		   String queryCtmName = request.getParameter("queryCtmName")==null?"":request.getParameter("queryCtmName");
		   String queryRtmCode = request.getParameter("queryRtmCode")==null?"":request.getParameter("queryRtmCode");
		   String queryRtmName = request.getParameter("queryRtmName")==null?"":request.getParameter("queryRtmName");
		   String emp_area_code = request.getParameter("emp_area_code")==null?"":request.getParameter("emp_area_code");
		   String curpage = request.getParameter("curpage")==null?"1":request.getParameter("curpage");
		   
		   LoginUserBeen userBean = (LoginUserBeen)request.getSession(false).getAttribute("loginuser");
		   String role  = userBean.getLoginRole();	
		   CommonBiz biz = new CommonBiz(userBean);
		   if("zongbu1shiyebu".indexOf(role)>=0){
				 request.setAttribute("areaList", biz.getAreaList());
			}else if("RTM".equals(role)){
				 ArrayList<AreaBen> ary = new ArrayList<AreaBen>();
				 AreaBen bean = new AreaBen();
				 bean.setAreaCode(userBean.getEara_code());
				 bean.setAreaValue(userBean.getEara());
				 request.setAttribute("areaList", ary);
				 emp_area_code = userBean.getEara_code()==null?"":userBean.getEara_code();
				 queryRtmName = userBean.getLoginUserName()==null?"":userBean.getLoginUserName();
				 queryRtmCode = userBean.getEmp_code()==null?"":userBean.getEmp_code();
			}else {//CTM&&其他
				 ArrayList<AreaBen> ary = new ArrayList<AreaBen>();
				 AreaBen bean = new AreaBen();
				 bean.setAreaCode(userBean.getEara_code());
				 bean.setAreaValue(userBean.getEara());
				 request.setAttribute("areaList", ary);
				 emp_area_code = userBean.getEara_code()==null?"":userBean.getEara_code();
				 queryCtmName = userBean.getLoginUserName();
			}	
		   
		   CtmGradeBiz  manegeBiz= new CtmGradeBiz();
		   PageNavigator pageNav = new PageNavigator();
		   if(!curpage.equals(""))
			   pageNav.setCurpage(Integer.parseInt(curpage));
		   ArrayList<String> param = new ArrayList<String>();
		   param.add(queryyyyymm);
		   param.add(emp_area_code);
		   param.add(queryCtmName);
		   param.add(queryCtmCode);
		   param.add(queryRtmName);
		   param.add(queryRtmCode);
	
		   PageBean pageBean  = manegeBiz.queryCtmGradeList(pageNav, param); 
		   
		   request.setAttribute("pageBean", pageBean);
		   request.setAttribute("emp_area_code", emp_area_code);
		   request.setAttribute("queryyyyymm", queryyyyymm);
		   request.setAttribute("queryCtmCode", queryCtmCode);
		   request.setAttribute("queryCtmName", queryCtmName);
		   request.setAttribute("queryRtmCode", queryRtmCode);
		   request.setAttribute("queryRtmName", queryRtmName);
		   return "success";
	   }
	
	   public void setServletRequest(HttpServletRequest request) {
		     this.request = request;
		   }
}
